package com.cjkj.system.api.factory;

import com.cjkj.common.core.domain.R;
import com.cjkj.system.api.RemoteWarnService;
import com.cjkj.system.api.domain.APIWarnHandle;
import com.cjkj.system.api.domain.APIWarnRecords;
import com.cjkj.system.api.domain.request.WarnListReq;
import com.cjkj.system.api.domain.request.WarnRecordReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteWarnFallbackFactory implements FallbackFactory<RemoteWarnService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);

    @Override
    public RemoteWarnService create(Throwable cause) {
        log.error("系统服务调用失败:{}", cause.getMessage());
        return new RemoteWarnService() {

            @Override
            public R<APIWarnRecords> listWarn(WarnListReq req) {
                return R.fail(req.getHospitalId()+","+req.getDeptId()+":查询预警提示记录失败");
            }
            @Override
            public R<Boolean> handleWarns(List<APIWarnHandle> apiWarnHandleList) {
                return R.fail("处理预警失败");
            }

            @Override
            public R<Boolean> handleWarns(WarnRecordReq req) {
                return R.fail(req.getVisitNo()+"处理预警失败");
            }

            @Override
            public R<APIWarnRecords> listWarns(Long visitNo, String expectOutTime) {
                return R.fail(visitNo+"获取预警消息失败");
            }
        };
    }
}
